<template>
  <div class='regiment first-box'>
    <Head :tabData="tabData" :selectIndex="selectIndex" :changeFun="changeSelect"></Head>
    <GreyLine></GreyLine>
    <Scroll :hasmore="hasmore" :pullup="pullup" setHeight="-70">
      <List :selectIndex="selectIndex" :listData="listData" :buttonData="buttonData"></List>
    </Scroll>
  </div>
</template>
<script>
import Head from './common/tab'
import GreyLine from '../../common/line.vue'
import Scroll from '../../common/scroller'
import List from './common/list.vue'
export default {
  components: {Head,GreyLine,Scroll,List},
  name: "",
  data() {
    return {
      tabData:[
        {
          label:"新车专享",
          type:0,
        },{
          label:"全民参与",
          type:1,
        },
      ],
      listData:[
        {
          id:1,
          img:require('../../../assets/img/hpmepage/sense/1.png'),
          title:"优惠专享 | 免费洗车",
          price:1, //现价
          cost:35,//原价
          group:3,//几人团
        },{
          id:1,
          img:require('../../../assets/img/hpmepage/sense/1.png'),
          title:"优惠专享 | 免费洗车",
          price:1, //现价
          cost:35,//原价
          group:3,//几人团
        }
      ],

      buttonData:[
        {
          label:"去参团",
          click:this.open,
          type:1
        },{
          label:"去开团",
          click:this.open,
          type:2
        }
      ],

      selectIndex:0,//默认项
      pageInfo:{
        page:1
      },
      hasmore:false,
    };
  },
  methods: {
    changeSelect(index){
      this.selectIndex=index
      console.log("click---changetab")
      this.pageInfo.page=1
      this.listData=[]
      this.getList()
    },

    // 下拉刷新方法回调
    pullup(func){
      if(this.hasmore){
        this.pageInfo.page++
         _g.orderList([this.getList,func])
         return
      }
    },

    open(btn,item){
      sessionStorage.setItem("detailId",item.id)
      var urls=["/regiment/join","/regiment/open"]
      this.$router.push(urls[btn.type-1])
    },

    getList(){
      var params={
        teamRange:this.selectIndex,
        page:this.pageInfo.page
      }
      _g.apiPost("collage/init.do",params).then(res=>{
        if(res.status==1){
          var that=this
          this.$store.state.dialogs.alert.content=res.msg
          this.$store.state.dialogs.alert.show=true
          this.$store.state.dialogs.alert.OK=function(){
            that.$router.go(-1)
          }
          return
        }
        var goal=[]
        res.data.list.forEach(ele => {
            goal.push({
              id:ele.id,
              title:ele.name,
              img:ele.picture||"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535004363524&di=d92df07bf7f8cc565633f83a1e567d13&imgtype=0&src=http%3A%2F%2Fimage.bitautoimg.com%2Fappimage%2Fmedia%2F20180121%2Fw1080_h620_85868a7df2194a43bf3497ed27e56cdf.jpeg",
              price:ele.price,
              cost:ele.cose||12000,
              group:ele.teamMax||"1",
            })
        });
        this.$set(this,"listData",this.listData.concat(goal))
      })
    }
  },
  created() {
    this.changeSelect(0)
  }
};
</script>
<style lang="scss" scoped>
.regiment {
  
  .margin15{
    margin: 0 15px;      
  }
}
</style>